<script>
    $(function(){
        // 注册一些常用的函数 百度编辑器 webuploader上传等。
        EBCMS.CORE.myfun('tabs',function(a,b){
            $(a).children().bind('click', function(event) {
                $(this).addClass('current').siblings().removeClass('current');
                var i = $(this).index();
                $(b).children().eq(i).show().siblings().hide();
            });
            $(a).children().eq(0).trigger('click');
        });

        EBCMS.CORE.myfun('renderUE',function(contain,option){
            window.UEDITOR_CONFIG.initialFrameHeight = '300';
            window.UEDITOR_CONFIG.zIndex = '1500';
            window.UEDITOR_CONFIG.initialFrameWidth = 'auto';
            window.UEDITOR_CONFIG.UEDITOR_HOME_URL = '{:get_root()}/third/ueditor/';
            window.UEDITOR_CONFIG.serverUrl = '{:url('ebcms/index/ueditor')}';
            var options = {
                initialFrameWidth:"100%",
                scaleEnabled:true,
            };
            if (option && typeof option == 'object') {
                $.extend(options,option);
            };
            UE.getEditor(contain,options);
        });

        EBCMS.CORE.myfun('renderUploader',function(pick,success,extension,path){
            var extensions = extension?extension:'gif,jpg,jpeg,bmp,png,zip,rar';
            var uploader = WebUploader.create({
                auto: true,
                swf: '/webuploader/Uploader.swf',
                server: '{:url('ebcms/index/upload')}',
                pick: pick,
                duplicate:true,
                accept: {
                    extensions: extensions,
                },
                formData:{
                    path:path,
                }
            });
            $(pick).mouseover(function(){
                $(this).resize();
            });
            uploader.on('error', function(code) {
                switch(code){
                    case 'Q_EXCEED_NUM_LIMIT':
                        EBCMS.MSG.alert('文件数量超出限定值！');
                    break;
                    case 'Q_EXCEED_SIZE_LIMIT':
                        EBCMS.MSG.alert('文件大小超出限制！');
                    break;
                    case 'Q_TYPE_DENIED':
                        EBCMS.MSG.alert('禁止上传该类型的文件！');
                    break;
                    default:
                        EBCMS.MSG.alert('上传文件重复！');
                }
            });
            uploader.on('uploadSuccess', function(file,res) {
                if (typeof success == 'function') {
                    success(file,res);
                }
            });
            uploader.on('uploadError', function( file ) {
                EBCMS.MSG.alert('上传出错');
            });
            uploader.on('uploadComplete', function( file ) {
                // EBCMS.MSG.show('上传完成');
            });
        });

        EBCMS.MYFUN.tabs('#{$form.unique}_tabs','#{$form.unique}_tabboxs');

    });
</script>
<form id="{$form.unique}Form">
    {if condition='count($groups)>1'}
    <table class="table table-form">
        <tr>
            <th></th>
            <td>
                <div class="tabs" id="{$form.unique}_tabs">
                    {foreach $groups as $key => $fields} 
                        <div class="tab-head">{$key}</div>
                    {/foreach}
                </div>
            </td>
        </tr>
    </table>
    {else/}
    <style>
        .tabboxs .tab-body{
            display: block;
        }
    </style>
    {/if}
    <div class="tabboxs" id="{$form.unique}_tabboxs">
        {foreach $groups as $key => $fields}
            <div class="tab-body">
                <div class="table-responsive">
                    <table class="table table-form" style="min-width: 300px;">
                        {foreach $fields as $key => $field}
                            
                            {include file='ebcms@common/formfield' /}
                        {/foreach}
                    </table>
                </div>
            </div>
        {/foreach}
    </div>
</form>